﻿@model GAE_PI.Models.DetailActivityModel

@{
    ViewBag.Title = "ModifierActivite";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>ModifierActivite</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>


<script>
    $(document).ready(function () {
        $('#imagesAdd').click(function () {
            var num = $('.clonedImage').length - 1; // how many "duplicatable" input fields we currently have
            var newNum = new Number(num + 1);      // the numeric ID of the new input field being added

            // create the new element via clone(), and manipulate it's ID using newNum value
            var newElem = $('#images' + num).clone().attr('id', 'images' + newNum);

            // manipulate the name/id values of the input inside the new element
            newElem.children(':first').attr('id', 'images_' + newNum + '_').attr('name', 'images[' + newNum + ']');

            // insert the new element after the last "duplicatable" input field
            $('#images' + num).after(newElem);

            // enable the "remove" button
            $('#imagesDel').removeAttr("disabled");
        });

        $('#imagesDel').click(function () {
            var num = $('.clonedImage').length - 1; // how many "duplicatable" input fields we currently have
            $('#images' + num).remove();     // remove the last element

            // enable the "add" button
            $('#imagesAdd').removeAttr("disabled");

            // if only one element remains, disable the "remove" button
            if (num == 1)
                $('#imagesDel').attr('disabled', 'disabled');
        });
        if ($('.clonedImage').length == 1)
            $('#imagesDel').attr('disabled', 'disabled');


        $('#datesAdd').click(function () {
            var num = $('.clonedDate').length - 1; // how many "duplicatable" input fields we currently have
            var newNum = new Number(num + 1);      // the numeric ID of the new input field being added

            // create the new element via clone(), and manipulate it's ID using newNum value
            var newElem = $('#Dates' + num).clone().attr('id', 'Dates' + newNum);

            // manipulate the name/id values of the input inside the new element
            newElem.children(':first').attr('id', 'Dates_' + newNum + '_').attr('name', 'Dates[' + newNum + ']');

            // insert the new element after the last "duplicatable" input field
            $('#Dates' + num).after(newElem);

            // enable the "remove" button
            $('#datesDel').removeAttr("disabled");
        });

        $('#datesDel').click(function () {
            var num = $('.clonedDate').length - 1; // how many "duplicatable" input fields we currently have
            $('#dates' + num).remove();     // remove the last element

            // enable the "add" button
            $('#datesAdd').removeAttr("disabled");

            // if only one element remains, disable the "remove" button
            if (num == 1)
                $('#datesDel').attr('disabled', 'disabled');
        });
        if ($('.clonedDate').length == 1)
            $('#datesDel').attr('disabled', 'disabled');

    });
</script>
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>DetailActivityModel</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Nom)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Nom)
            @Html.ValidationMessageFor(model => model.Nom)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.MinInscription)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MinInscription)
            @Html.ValidationMessageFor(model => model.MinInscription)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.MaxInscription)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MaxInscription)
            @Html.ValidationMessageFor(model => model.MaxInscription)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Prix)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Prix)
            @Html.ValidationMessageFor(model => model.Prix)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Etat)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Etat)
            @Html.ValidationMessageFor(model => model.Etat)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Responsables)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Responsables)
            @Html.ValidationMessageFor(model => model.Responsables)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>
        <div class="editor-label">Images * @Html.ValidationMessageFor(model => model.Images)</div>
        @{
            var imagesCount = 0;
            foreach (String item in Model.Images)
            {
                <div id="images@(imagesCount)" class="editor-field clonedImage">
                    <input class="text-box single-line" id="images_@(imagesCount)_" name="images[@(imagesCount)]" type="text" value="@item" />
                </div>
                imagesCount++;
            }
        }
        <div>
            <input type="button" id="imagesAdd" value="Ajouter une image" />
            <input type="button" id="imagesDel" value="Supprimer une image" />
        </div>



        <div class="editor-label">Dates * @Html.ValidationMessageFor(model => model.Dates)</div>
        @{
            var datesCount = 0;
            foreach (String item in Model.Dates)
            {
                <div id="dates@(datesCount)" class="editor-field clonedDate">
                    <input class="text-box single-line" id="dates_@(datesCount)_" name="dates[@(datesCount)]" type="text" value="@item" />
                </div>
                datesCount++;
            }
        }
        <div>
            <input type="button" id="datesAdd" value="Ajouter une date" />
            <input type="button" id="datesDel" value="Supprimer une date" />
        </div>
        <p>
            <input type="submit" name="Valider" value="Valider" />
        </p>
    </fieldset>
}



<div>
    @Html.ActionLink("Back to List", "Index", null, new { @class = "button" })
</div>

